#ifndef _mat2array_h_
#define _mat2array_h_

#include <arrayfire.h>
#include <opencv2/opencv.hpp>

class Converter {
// Convert from cv::Mat to af::array (fast)
// Host memory is allocated once during 
// object construction for speed.
// It is assumed that the size of 
// input cv::Mat object does not change
// The class can be used in video processing

private:
	af::dim4 sz;	// data dimentions
	float *dataPtr;	// pointer to pinned host memory 
	cv::Mat data_float; // cv:Mat as float
	af::array ind;  // conversion indices

	// allocate pinned host memory
	void allocateMemory();

public:
	Converter(cv::Size data_sz, int nchannels);

	// convert to array
	af::array to_array(cv::Mat data);

	// free pinned memory
	void free() { af::array::free(dataPtr); }
};

#endif